package com.survey.system.controller;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.survey.common.core.domain.entity.SysUser;
import com.survey.system.domain.SurIssueType;
import com.survey.system.service.ISysUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.survey.common.annotation.Log;
import com.survey.common.core.controller.BaseController;
import com.survey.common.core.domain.AjaxResult;
import com.survey.common.enums.BusinessType;
import com.survey.system.domain.SurIssuePreset;
import com.survey.system.service.ISurIssuePresetService;
import com.survey.common.utils.poi.ExcelUtil;
import com.survey.common.core.page.TableDataInfo;

/**
 * 预设问题Controller
 * 
 * @author ruoyi
 * @date 2024-12-25
 */
@RestController
@RequestMapping("/system/preset")
public class SurIssuePresetController extends BaseController
{
    @Autowired
    private ISurIssuePresetService surIssuePresetService;
    @Autowired
    private ISysUserService sysUserService;

    /**
     * 查询预设问题列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SurIssuePreset surIssuePreset)
    {
        List<SurIssuePreset> result = surIssuePresetService.selectSurIssuePresetList(surIssuePreset);
        startPage();
        return getDataTable(result);
    }

    /**
     * 导出预设问题列表
     */
    @Log(title = "预设问题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SurIssuePreset surIssuePreset)
    {
        List<SurIssuePreset> list = surIssuePresetService.selectSurIssuePresetList(surIssuePreset);
        ExcelUtil<SurIssuePreset> util = new ExcelUtil<SurIssuePreset>(SurIssuePreset.class);
        util.exportExcel(response, list, "预设问题数据");
    }

    /**
     * 获取预设问题详细信息
     */
    @GetMapping(value = "/{preId}")
    public AjaxResult getInfo(@PathVariable("preId") Long preId)
    {
        return success(surIssuePresetService.selectSurIssuePresetByPreId(preId));
    }

    /**
     * 新增预设问题
     */
    @Log(title = "预设问题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SurIssuePreset surIssuePreset)
    {
        surIssuePreset.setCreateBy(getUsername());
        return toAjax(surIssuePresetService.insertSurIssuePreset(surIssuePreset));
    }

    /**
     * 修改预设问题
     */
    @Log(title = "预设问题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SurIssuePreset surIssuePreset)
    {
        surIssuePreset.setUpdateBy(getUsername());
        return toAjax(surIssuePresetService.updateSurIssuePreset(surIssuePreset));
    }

    /**
     * 删除预设问题
     */
    @Log(title = "预设问题", businessType = BusinessType.DELETE)
	@DeleteMapping("/{preIds}")
    public AjaxResult remove(@PathVariable Long[] preIds)
    {
        return toAjax(surIssuePresetService.deleteSurIssuePresetByPreIds(preIds));
    }

    /**
     * 修改状态
     */
    @Log(title = "问题类型", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody SurIssuePreset surIssuePreset)
    {
        surIssuePreset.setUpdateBy(getUsername());
        return toAjax(surIssuePresetService.updateSurIssuePreset(surIssuePreset));
    }
}
